package dialog;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.zx.theline.jclr.JclrActivity;
import com.example.zx.theline.R;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import GsonBean.JdjclrxqBean;
import GsonBean.RjhsgxmList;
import GsonBean.SuccessBean;
import GsonBean.post.SaveCaoGaoPost;
import Utils.RefreshManager;
import app.MyApplication;
import base.BaseDialog;
import network.NetWorkApi;
import network.ObjectHttpResponseHandler;
import Utils.MyToast;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by zx on 2017/4/10.
 */
//是否检查完成提示框， 检查完成 或者整改下达
public class IsFinishDialog extends BaseDialog {

//    //检查完成
//    TextView jcwc;
//
    //信息类型
    TextView xxlx;

    //取消
    TextView qx;

    //确定
    TextView qd;

    TjwcDialog mTjwcDialog;

    //要发送的数据实体类
    SaveCaoGaoPost mSaveCaoGaoPost;
    RjhsgxmList mRjhsgxmList;


    JdjclrxqBean mJdjclrxqBean;

    Activity BaseActivity;

    public IsFinishDialog(Context context, SaveCaoGaoPost mSaveCaoGaoPost, Activity activity) {
        super(context);
        BaseActivity=activity;
        this.mSaveCaoGaoPost = mSaveCaoGaoPost;

    }

    public IsFinishDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_isfinish);
        InitView();
        InitData();
        InitListen();
    }

    @Override
    protected void InitView() {
        qx = (TextView) findViewById(R.id.qx);
        qd = (TextView) findViewById(R.id.qd);
        xxlx = (TextView) findViewById(R.id.xxlx);
//        zgxd = (TextView) findViewById(R.id.zgxd);
    }

    @Override
    protected void InitData() {
        if(mSaveCaoGaoPost.getJcbtype()!=null){
            xxlx.setText(mSaveCaoGaoPost.getJcbtype());
        }

    }

    @Override
    protected void InitListen() {

        qd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                设置表状态 检查完成为400
                MyApplication.ShowWaitDialog(getContext());
                //填充内部检查表status 400 检查完成 方便后台读取
                for(SaveCaoGaoPost.LjyyxRjdjhjcbShdw bean:mSaveCaoGaoPost.getJcbShdwList()){
                    bean.setJcbstatus("400");
                }
                mSaveCaoGaoPost.setJcbstatus("400");
                NetWorkApi.tjwc(mSaveCaoGaoPost, new Callback<SuccessBean>() {
                            @Override
                            public void onResponse(Call<SuccessBean> call, Response<SuccessBean> response) {
                                try {
                                    MyApplication.HideWaitDialog();
                                    SuccessBean mBean = response.body();
                                    if (mBean.getMsg().equals("success") && mBean.getCount() == 1) {
                                        MyToast.showToast("检查完成");
                                        RefreshManager.Jdjc.RefreshJdjclrxx();
                                        RefreshManager.Jdjc.RefreshJdjcdcl();
                                        RefreshManager.Jdjc.RefreshJdjcycl();
                                        IsFinishDialog.this.dismiss();
                                        getContext().startActivity(new Intent(getContext(), JclrActivity.class));

                                    } else {
                                        MyToast.showToast("提交失败");
                                    }
                                } catch (Exception e) {
                                    MyToast.showFail();
                                }
                                MyApplication.HideWaitDialog();
                            }

                            @Override
                            public void onFailure(Call<SuccessBean> call, Throwable t) {
                                MyToast.showFail();
                            }
                        }
                );
            }

        });

        qx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IsFinishDialog.this.dismiss();
            }
        });
    }


}
